class GUI

This class encapsulates the overall GUI. It is the main UI window that is displayed when the program is started. It also manages timing and coordination between the visualization and the underlying simulation.

Public Class Methods

new(simulation) click to toggle source

Initializes a GUI instance with a simulation backing it. The window is shown.

Calls superclass method
# File lib/gui.rb, line 13
def initialize(simulation)
  super()
  @simulation = simulation
  @time = Time.now

  # Close button quits application
  signal_connect("destroy") do
    Gtk.main_quit
    false
  end

  set_title "From Hunter-gatherers to Agriculture"
  set_border_width 10
  set_default_size(640, 480)

  @notebook = create_notebook # tab interface

  # Timing state
  @running = false
  @speed = 15
  @progress = 0
  @iterations = 100
  @last_sim = Time.now

  reset_gui
end

Public Instance Methods

gtk_main() click to toggle source

Begins the main Gtk loop. This is a blocking call and the Gtk loop will take control of the thread it is called from.

# File lib/gui.rb, line 61
def gtk_main
  Gtk.main
end
reset_gui() click to toggle source

Resets all the user interface elements to the state they were when the application was started.

# File lib/gui.rb, line 42
def reset_gui
  each { |c| remove(c) } # Remove all child widgets
  @gui_scape = GUIScape.new(@simulation.scape)
  ui = create_root_box(create_controls, @gui_scape)
  @population_graph = GUIGraph.new
  @resources_graph = GUIGraph.new

  @notebook.append_page(ui, Gtk::Label.new("Simulation"))
  @notebook.append_page(@population_graph, Gtk::Label.new("Population graph"))
  @notebook.append_page(@resources_graph, Gtk::Label.new("Resources graph"))
  @notebook.set_page(0)

  add(@notebook)
  show_all
end